var t = getApp(), a = require("../../../utils/themeSkin/skinBehavior");

Page({
    behaviors: [ a ],
    data: {
        goodsList: [],
        query: {
            page: 1,
            longitude: "",
            latitude: "",
            city: "",
            cityCode: "",
            travel_around_goods_type: 0,
            is_recommand: 0,
            category: 0,
            title: "",
            basic_info: 1
        },
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        siteName: "",
        imageUrl: ""
    },
    onLoad: function(t) {
        var a;
        "" !== (null !== (a = t.keyword) && void 0 !== a ? a : "") && this.setData({
            "query.title": t.keyword.trim()
        }), this.setData({
            "query.city": t.city,
            "query.cityCode": t.cityCode,
            "query.latitude": t.latitude,
            "query.longitude": t.longitude,
            "query.page": 1
        });
        var e, o = wx.getStorageSync("searchHistory") || [];
        o.length > 0 && ((o = JSON.parse(o)).length >= 10 && o.pop());
        var i = Date.parse(new Date());
        o.unshift({
            name: this.data.query.title,
            key: i
        }), e = o.filter(function(t, a, e) {
            return e.findIndex(function(a) {
                return a.name === t.name;
            }) === a;
        }), wx.setStorageSync("searchHistory", JSON.stringify(e)), this.getGoodsList();
    },
    changeTitle: function(t) {
        this.setData({
            "query.page": 1,
            "query.title": t.detail.value
        });
    },
    goodsNavTo: function(t) {
        var a = t.currentTarget.dataset.goodsid;
        wx.navigateTo({
            url: "/packageF/tourAround/tourAroundGoodsDetails/tourAroundGoodsDetails?goodsId=" + a
        });
    },
    confirmTap: function(t) {
        this.setData({
            "query.page": 1,
            "query.title": t.detail.value
        }), this.getGoodsList();
    },
    searchClick: function() {
        this.getGoodsList();
    },
    getGoodsList: function() {
        var a = this, e = t.getNetAddresss("plugin.travel-around.frontend.goods.goods.getGoodsList");
        t._postNetWork({
            url: e,
            data: this.data.query,
            success: function(t) {
                var e = t.data;
                if (wx.hideLoading(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(), 1 == e.result) {
                    var o, i, n, r;
                    a.data.totalPage = e.data.last_page;
                    var d = e.basic_info;
                    a.data.totalPage || (a.data.totalPage = 0), a.setData({
                        goodsList: e.data.data,
                        siteName: null == d || null === (o = d.home) || void 0 === o || null === (i = o.mailInfo) || void 0 === i ? void 0 : i.name,
                        imageUrl: null == d || null === (n = d.home) || void 0 === n || null === (r = n.mailInfo) || void 0 === r ? void 0 : r.logo_url
                    });
                } else a.data.query.page = a.data.query.page - 1, a.isLoadMore = !1, wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var a = this;
        if (this.data.isLoadMore = !1, !(this.data.query.page >= this.data.totalPage)) {
            this.data.query.page = this.data.query.page + 1;
            var e = t.getNetAddresss("plugin.travel-around.frontend.goods.goods.getGoodsList");
            t._getNetWork({
                url: e,
                data: this.data.query,
                success: function(t) {
                    var e = t.data, o = e.data.data;
                    1 == e.result ? (a.data.isLoadMore = !0, a.setData({
                        goodsList: a.data.goodsList.concat(o)
                    })) : (a.data.query.page = a.data.query.page - 1, a.isLoadMore = !1, wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        wx.showNavigationBarLoading(), wx.showLoading({
            title: "刷新中..."
        });
        this.setData({
            query: {
                page: 1,
                longitude: "",
                latitude: "",
                city: "",
                travel_around_goods_type: 0,
                is_recommand: 0,
                category: 0,
                title: ""
            }
        }), this.getGoodsList();
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {
        return {
            title: "周边游-" + this.data.siteName,
            imageUrl: this.data.imageUrl,
            path: "/packageF/tourAround/tourSearchPage/tourSearchPage?keyword=".concat(this.data.query.title, "&city=").concat(this.data.query.city, "&latitude=").concat(this.data.query.latitude, "&longitude=").concat(this.data.query.longitude, "&cityCode=").concat(this.data.query.cityCode)
        };
    },
    onShareTimeline: function() {
        return {
            title: "周边游-" + this.data.siteName,
            imageUrl: this.data.imageUrl,
            path: "/packageF/tourAround/tourSearchPage/tourSearchPage?keyword=".concat(this.data.query.title, "&city=").concat(this.data.query.city, "&latitude=").concat(this.data.query.latitude, "&longitude=").concat(this.data.query.longitude, "&cityCode=").concat(this.data.query.cityCode)
        };
    }
});